package com.example.web;

import java.util.Date;
import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author Administrator
 * 
 */
public class WebContextListener implements ServletContextListener {

	Timer GCTimer = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @seejavax.servlet.ServletContextListener#contextDestroyed(javax.servlet.
	 * ServletContextEvent)
	 */
	public void contextDestroyed(ServletContextEvent arg0) {
		// 监听到程序关闭时执行...
		GCTimer.cancel();
		System.out.println(new Date().toString()+" [INFO] web project closed ...");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.servlet.ServletContextListener#contextInitialized(javax.servlet
	 * .ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent arg0) {
		// 监听到程序启动时执行...
		System.out.println(new Date().toString()+" [INFO] web project starting ...");
		GCTimer = new Timer(true);
		GCTimer.schedule(new GarbageCollectionTimer(), 1000, 1000*60*60*24);
	}

}
